home *** CD-ROM | disk | FTP | other *** search
/ Computer Inter@ctive 17 / Computer Interactive cdrom 17 - gen 99.iso / ZDNETIT / CONTENT / OPTIVDOS.ZIP / INCLUDE.ZIP / NEWCPLX.H < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-21  |  63.3 KB  |  1,342 lines

  1. /* newcmplx.h
  2.  
  3.     Include-File for the CMATH Complex Number Library
  4.     replaces <complex.h>.
  5.  
  6.     Copyright (C) 1996-1998 Martin Sander
  7.     Address of the author:
  8.            Martin Sander 
  9.            Sertⁿrnerstr. 11
  10.            D-37085 G÷ttingen
  11.            Germany
  12.            e-mail: MartinSander@Bigfoot.com
  13.  
  14.     for C++, the following classes are defined:
  15.     a) if you choose the "classic" Borland C++ style:  class complex;
  16.     b) otherwise:
  17.        classes complex<float>, complex<double>, and complex<long double>.
  18.     fComplex, dComplex, and eComplex are defined as synonyms for these classes.
  19.  
  20.     Fo plain C, use <cmath.h> instead, which declares fComplex, dComplex,
  21.     and eComplex as structs, along with the same range of functions as
  22.     present in the complex C++ classes.
  23.  
  24.     The classes complex and complex<double> are binary compatible with
  25.     the C struct dComplex. Similarly, complex<float> and struct fComplex
  26.     as well as class complex<long double> and struct eComplex are mutually
  27.     compatible. This is important if one has programs with some modules
  28.     written in C, others in C++.
  29.  
  30.     All mathematical complex functions are implemented as a library
  31.     written in Assembler language. In comparison to C++ inline functions,
  32.     this leads to greater precision, greater speed and best security due
  33.     to complete error handling via the standard C error handling functions
  34.     _matherr() (for complex<float> and complex<double>)
  35.     and _matherrl() (for complex<long double>).
  36.  
  37.     The declarations for the Standard Library complex classes have
  38.     partly been adapted from the implementation by Rogue Wave Software, Inc.
  39.     The function bodies, however, are completely new.
  40.  
  41.     Note the following important differences between this implementation
  42.     and the one contained in <complex.h>:
  43.     -  The real and imaginary parts are declared as public and are referred
  44.        to as  Re and Im, so that you may always access them as z.Re and z.Im
  45.        in addition to the member functions real(z) and imag(z);
  46.     -  The argument of all mathematical functions is a value, not a reference.
  47.     -  The following functions and operators have been added:
  48.        friend complex  cubic(complex);  //   third power
  49.        friend complex  inv(complex);    //   1.0 / z
  50.        friend complex  ipow(complex __base, int __expo);  // integer power
  51.        friend complex  log2(complex);
  52.        friend complex  powReExpo(complex __base, double __expoRe);
  53.                                        // explicit power with real exponent
  54.        friend complex  powReBase(double __baseRe, complex __expo);
  55.                                        // explicit power of real base
  56.        friend complex  quartic(complex);  // fourth power
  57.        friend complex  square(complex);
  58.        friend int      operator==(complex &, double);
  59.        friend int      operator!=(complex &, double);
  60.        Also new are many of the mixed-accuracy level binary operators.
  61. */
  62.  
  63. #ifndef __cplusplus
  64. #error Must use C++ for complex classes. Include <cmath.h> for the plain-C version
  65. #endif
  66. #if !defined(__NEWCPLX_H)
  67. #define __NEWCPLX_H
  68.  
  69.  
  70.       /* define _VFAR to get around the buggy definition of _FAR : */
  71. #if defined __SMALL__ || defined __MEDIUM__
  72.      #define   _VFAR  near   /* even in case of DS!=SS  */
  73. #elif defined __FLAT__ || defined _WIN32
  74.      #define  _VFAR
  75. #else
  76.      #define   _VFAR  far
  77. #endif
  78. #ifdef __BORLANDC__
  79.      #pragma option -a-
  80.      #if (__BORLANDC__ >= 0x450)
  81.          #define __cmf _RTLENTRY _EXPFUNC
  82.          #define __cmo _RTLENTRY
  83.     #else
  84.          #define __cmf  _Cdecl _FARFUNC
  85.          #define __cmo  _Cdecl
  86.     #endif
  87.     #if __BORLANDC__ < 0x500
  88.         #define VBOOL int
  89.     #else
  90.         #define VBOOL bool
  91.     #endif
  92. #else /* Visual C++, Watcom */
  93.      #pragma pack( push,1 )
  94.      #define VBOOL int
  95.      #define __cmf _cdecl
  96.      #define __cmo _cdecl
  97. #endif /* avoid insertion of dummy bytes  */
  98. #define _VFARC const _VFAR
  99.  
  100. #if !defined(__IOSTREAM_H)
  101. #include <iostream.h>
  102. #endif
  103.  
  104. #if defined( CMATH_CLASSIC_COMPLEX )
  105.       // classic Borland C++ class complex only. This has double precision.
  106.       // complex numbers of float and of long double precision are
  107.       // implemented as structs. So there is no constructor! Moreover, there
  108.       // are no functions defined for the float and long double complex numbers.
  109. #if !defined(__IOSTREAM_H)
  110. #include <iostream.h>
  111. #endif
  112.  
  113. #if !defined(RC_INVOKED)
  114.  
  115. #if defined(__BCOPT__)
  116. #if !defined(__FLAT__) && ((__BORLANDC__ < 0x450) || !defined(_RTL_ALLOW_po))
  117. #pragma option -po-     // disable Object data calling convention
  118. #endif
  119. #endif
  120.  
  121. #pragma option -Vo-
  122.  
  123. #if defined(__STDC__)
  124. #pragma warn -nak
  125. #endif
  126.  
  127. #endif  /* !RC_INVOKED */
  128.  
  129. #if(__BORLANDC__ >= 0x450)
  130. class _EXPCLASS complex {
  131. #else
  132. _CLASSDEF(complex)
  133. class _CLASSTYPE complex {
  134. #endif
  135.   public:
  136.     // constructors
  137.     complex( double Re_part, double Im_part ) {Re=Re_part; Im=Im_part;}
  138.     complex( double Re_part )  {Re=Re_part; Im=0;}
  139.     complex() {}; // more efficient to have these three separate variants
  140.     // Cartesian complex from polar coordinates:
  141.     friend complex __cmf polar(double _mag, double _angle=0);
  142.     // basic operations:
  143.     double real() { return Re; }                     // real part
  144.     double real(complex _VFARC &_z) { return _z.Re; }
  145.     double imag() { return Im; }                     // imaginary part
  146.     double imag(complex _VFARC &_z) { return _z.Im; } // imaginary part
  147.     friend complex __cmf neg(complex _VFARC &);   // same as unary operator -
  148.     friend complex __cmf conj(complex _VFARC &);  // complex conjugate
  149.     friend double  __cmf norm(complex _VFARC &);  // square of the magnitude
  150.     friend double  __cmf arg(complex);           // angle in the plane
  151.  
  152.      // Unary operators
  153.     complex _VFAR & __cmo operator+();
  154.     friend complex _VFAR & __cmf operator-( complex _VFARC &);
  155.  
  156.     // Binary operators
  157.     friend complex __cmf operator+(complex _VFARC &, complex _VFARC &);
  158.     friend complex __cmf operator+(double, complex _VFARC &);
  159.     friend complex __cmf operator+(complex _VFARC &, double);
  160.     friend complex __cmf operator-(complex _VFARC &, complex _VFARC &);
  161.     friend complex __cmf operator-(double, complex _VFARC &);
  162.     friend complex __cmf operator-(complex _VFARC &, double);
  163.     friend complex __cmf operator*(complex _VFARC &, complex _VFARC &);
  164.     friend complex __cmf operator*(complex _VFARC &, double);
  165.     friend complex __cmf operator*(double, complex _VFARC &);
  166.     friend complex __cmf operator/(complex _VFARC &, complex _VFARC &);
  167.     friend complex __cmf operator/(complex _VFARC &, double);
  168.     friend complex __cmf operator/(double, complex _VFARC &);
  169.  
  170.     friend VBOOL __cmf operator==(complex _VFARC &, complex _VFARC &);
  171.     friend VBOOL __cmf operator==(complex _VFARC &, double);
  172.     friend VBOOL __cmf operator!=(complex _VFARC &, complex _VFARC &);
  173.     friend VBOOL __cmf operator!=(complex _VFARC &, double);
  174.  
  175.     complex _VFAR & __cmo operator+=(complex _VFARC &);
  176.     complex _VFAR & __cmo operator+=(double);
  177.     complex _VFAR & __cmo operator-=(complex _VFARC &);
  178.     complex _VFAR & __cmo operator-=(double);
  179.     complex _VFAR & __cmo operator*=(complex _VFARC &);
  180.     complex _VFAR & __cmo operator*=(double);
  181.     complex _VFAR & __cmo operator/=(complex _VFARC &);
  182.     complex _VFAR & __cmo operator/=(double);
  183.  
  184.     // Overloaded ANSI C math functions with error handling via matherr():
  185.     friend double  __cmf abs(complex);    // complex pointer magnitude
  186.     friend complex __cmf acos(complex);
  187.     friend complex __cmf asin(complex);
  188.     friend complex __cmf atan(complex);
  189.     friend complex __cmf cos(complex);
  190.     friend complex __cmf cosh(complex);
  191.     friend complex __cmf cubic(complex);  // raise to the third power
  192.     friend complex __cmf exp(complex);
  193.     friend complex __cmf inv(complex);    //   1.0 / z
  194.     friend complex __cmf ipow(complex _base, int _IntExpo);  // integer power
  195.     friend complex __cmf ln(complex);
  196.     friend complex __cmf log(complex); // same as ln
  197.     friend complex __cmf log2(complex);
  198.     friend complex __cmf log10(complex);
  199.     friend complex __cmf pow(complex _base, double _expoRe);
  200.     friend complex __cmf powReExpo(complex _base, double _expoRe);
  201.     friend complex __cmf pow(double _baseRe, complex _expo);
  202.     friend complex __cmf powReBase(double _baseRe, complex _expo);
  203.     friend complex __cmf pow(complex _base, complex _expo);
  204.     friend complex __cmf quartic(complex);  // raise to the fourth power
  205.     friend complex __cmf sin(complex);
  206.     friend complex __cmf sinh(complex);
  207.     friend complex __cmf sqrt(complex);
  208.     friend complex __cmf square(complex);
  209.     friend complex __cmf tan(complex);
  210.     friend complex __cmf tanh(complex);
  211.  
  212.     friend ostream _VFAR & __cmf operator<<(ostream _VFAR &, complex _VFAR &);
  213.     friend istream _VFAR & __cmf operator>>(istream _VFAR &, complex _VFARC &);
  214.  
  215. // Implementation
  216.     double Re, Im;   // still public!
  217. };
  218. #if !defined( _CMATH_DEFS )
  219.    #define _CMATH_DEFS
  220.    typedef struct {float  Re, Im;} fComplex;
  221.    typedef complex  dComplex;
  222.    #ifdef __BORLANDC__
  223.        typedef long double  extended;
  224.        typedef struct {extended Re, Im;} eComplex;
  225.    #else /* Visual C++ */
  226.        typedef  double extended; /* Visual C++ does not support
  227.                                  80-bit IEEE numbers. So make
  228.                                  extended equal to double    */
  229.        typedef dComplex  eComplex;
  230.    #endif    /* restore default data packing  */
  231. #endif
  232.  
  233. // Inline implementation of the simplest functions and operators
  234. // basic operations:
  235. inline complex __cmo conj(complex _VFARC & __z)
  236. {    return complex(__z.Re, -__z.Im); }
  237.  
  238. inline complex __cmo neg(complex _VFARC & __z)
  239. {    return complex(-__z.Re, -__z.Im); }
  240.  
  241. // unary operators:
  242. inline complex _VFAR & __cmo complex::operator+()
  243. {    return *this; }
  244.  
  245. inline complex _VFAR & __cmf operator-( complex _VFARC & __z)
  246. {    return complex(-__z.Re, -__z.Im); }
  247.  
  248.  
  249. // binary operators:
  250. inline complex __cmo operator+(complex _VFARC & __z1, complex _VFARC & __z2)
  251. {    return complex(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  252.  
  253. inline complex __cmo operator+(double __z1Re, complex _VFARC & __z2)
  254. {    return complex(__z1Re + __z2.Re, __z2.Im); }
  255.  
  256. inline complex __cmo operator+(complex _VFARC & __z1, double __z2Re)
  257. {    return complex(__z1.Re + __z2Re, __z1.Im); }
  258.  
  259. inline complex __cmo operator-(complex _VFARC & __z1, complex _VFARC & __z2)
  260. {    return complex(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  261.  
  262. inline complex __cmo operator-(double __z1Re, complex _VFARC & __z2)
  263. {    return complex(__z1Re - __z2.Re, -__z2.Im); }
  264.  
  265. inline complex __cmo operator-(complex _VFARC & __z1, double __z2Re)
  266. {    return complex(__z1.Re - __z2Re, __z1.Im); }
  267.  
  268. inline complex __cmo operator*(complex _VFARC & __z1, complex _VFARC & __z2)
  269. {   return complex( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  270.                     __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  271. }
  272.  
  273. inline complex __cmo operator*(complex _VFARC & __z1, double __z2Re)
  274. {    return complex(__z1.Re*__z2Re, __z1.Im*__z2Re); }
  275.  
  276. inline complex __cmo operator*(double __z1Re, complex _VFARC & __z2)
  277. {    return complex(__z2.Re*__z1Re, __z2.Im*__z1Re); }
  278.  
  279. inline complex __cmo operator /(complex _VFARC & __dividend,
  280.                                 complex _VFARC & __divisor )
  281. {     complex     Result;
  282.       long double denom;
  283.       Result.Re = (double)((__dividend.Re *__divisor.Re +
  284.                             __dividend.Im *__divisor.Im) /
  285.          (denom = (long double)(__divisor.Re) * __divisor.Re +
  286.                   (long double)(__divisor.Im) * __divisor.Im));
  287.       Result.Im = (double)((__dividend.Im * __divisor.Re -
  288.                             __dividend.Re * __divisor.Im ) / denom);
  289.       return Result;
  290. }
  291.  
  292. inline complex __cmo operator/(complex _VFARC & __dividend, double __divisorRe)
  293. {    return complex(__dividend.Re/__divisorRe, __dividend.Im/__divisorRe); }
  294.  
  295. inline complex __cmo operator /( double __dividendRe, complex _VFARC & __divisor )
  296. {     complex     Result;
  297.       long double denom;
  298.       Result.Re = (double)((__dividendRe * __divisor.Re) /
  299.          (denom = (long double)(__divisor.Re) * __divisor.Re +
  300.                   (long double)(__divisor.Im) * __divisor.Im));
  301.       Result.Im = -(double)((__dividendRe * __divisor.Im ) / denom);
  302.       return Result;
  303. }
  304.  
  305. inline complex _VFAR & __cmo complex::operator+=(complex _VFARC & __z2)
  306. {   Re += __z2.Re;
  307.     Im += __z2.Im;
  308.     return *this;
  309. }
  310.  
  311. inline complex _VFAR & __cmo complex::operator+=(double __z2Re)
  312. {   Re += __z2Re;
  313.     return *this;
  314. }
  315.  
  316. inline complex _VFAR & __cmo complex::operator-=(complex _VFARC & __z2)
  317. {   Re -= __z2.Re;
  318.     Im -= __z2.Im;
  319.     return *this;
  320. }
  321.  
  322. inline complex _VFAR & __cmo complex::operator-=(double __z2Re)
  323. {   Re -= __z2Re;
  324.     return *this;
  325. }
  326.  
  327. inline complex _VFAR & __cmo complex::operator*=(double __z2Re)
  328. {   Re *= __z2Re;
  329.     Im *= __z2Re;
  330.     return *this;
  331. }
  332.  
  333. inline complex _VFAR & __cmo complex::operator *=(complex _VFARC & __z2)
  334. {     double tmpRe = Re * __z2.Re - Im * __z2.Im;
  335.              Im    = Re * __z2.Im + Im * __z2.Re;
  336.       Re = tmpRe;
  337.       return *this;
  338. }
  339.  
  340. inline complex _VFAR & __cmo complex::operator /=( complex _VFARC & __divisor )
  341. {     long double denom;
  342.       double tmpRe = (double)((Re * __divisor.Re + Im * __divisor.Im) /
  343.         (denom = (long double)(__divisor.Re) * __divisor.Re +
  344.                  (long double)(__divisor.Im) * __divisor.Im));
  345.       Im = (Im * __divisor.Re - Re * __divisor.Im ) / denom;
  346.       Re = tmpRe;
  347.       return *this;
  348. }
  349.  
  350. inline complex _VFAR & __cmo complex::operator/=(double __z2Re)
  351. {   Re /= __z2Re;
  352.     Im /= __z2Re;
  353.     return *this;
  354. }
  355.  
  356. inline VBOOL __cmo operator==(complex _VFARC & __z1, complex _VFARC & __z2)
  357. {   return __z1.Re == __z2.Re && __z1.Im == __z2.Im; }
  358.  
  359. inline VBOOL __cmo operator==(complex _VFARC & __z1, double __z2Re)
  360. {   return __z1.Re == __z2Re && __z1.Im == 0.0; }
  361.  
  362. inline VBOOL __cmo operator!=(complex _VFARC & __z1, complex _VFARC & __z2)
  363. {   return __z1.Re != __z2.Re || __z1.Im != __z2.Im; }
  364.  
  365. inline VBOOL __cmo operator!=(complex _VFARC & __z1, double __z2Re)
  366. {   return __z1.Re != __z2Re || __z1.Im != 0.0; }
  367.  
  368.  
  369. #if !defined(RC_INVOKED)
  370.  
  371. #if defined(__STDC__)
  372. #pragma warn .nak
  373. #endif
  374.  
  375. #pragma option -Vo.
  376.  
  377. #if defined(__BCOPT__)
  378. #if !defined(__FLAT__) && ((__BORLANDC__ < 0x450) || !defined(_RTL_ALLOW_po))
  379. #pragma option -po.     // restore Object data calling convention
  380. #endif
  381. #endif
  382.  
  383. #endif  /* !RC_INVOKED */
  384. #if !defined( _CMATH_DEFS )
  385.    #define _CMATH_DEFS
  386.    typedef struct {float  Re, Im;} fComplex;
  387.    typedef complex  dComplex;
  388.    #ifdef __BORLANDC__
  389.        typedef long double  extended;
  390.        typedef struct {extended Re, Im;} eComplex;
  391.    #else /* Watcom, Visual C++ */
  392.        typedef  double extended; /* Visual C++ and Optima++ do 
  393.                             not support 80-bit IEEE numbers. So 
  394.                             make extended equal to double    */
  395.        typedef dComplex  eComplex;
  396.    #endif    /* restore default data packing  */
  397. #endif
  398.  
  399. #else   // declare the complex classes for all three levels of precision
  400.         // Although these classes are fully compatible to the complex
  401.         // classes of the Standard C++ Library, keep them out of the
  402.         // standard namespace.
  403.  
  404. template <class T>
  405. class complex;
  406. class complex<float>;
  407. class complex<double>;
  408. class complex<long double>;
  409.  
  410. class complex<float>
  411. {
  412.   public:
  413.          // constructors:
  414.     #if defined __BORLANDC__ && __BORLANDC__ >= 0x450
  415.         complex( float Re_part, float Im_part ) {Re=Re_part; Im=Im_part;}
  416.         complex( float Re_part )  {Re=Re_part; Im=0;}
  417.         complex() {}; // most efficient to have these as three different constructors!
  418.             // interconversions between the three levels of accuracy:
  419.             // with OVERFLOW error handling for the down-conversions
  420.     #else // problems with the template definitions in older versions
  421.         complex<float>( float Re_part, float Im_part ) {Re=Re_part; Im=Im_part;}
  422.         complex<float>( float Re_part )  {Re=Re_part; Im=0;}
  423.         complex<float>() {}; // most efficient to have these as three different constructors!
  424.     #endif
  425.     #if !defined __BORLANDC__ || __BORLANDC__ > 0x500
  426.         complex<float> (complex<float> _VFARC &);
  427.     #endif
  428.     #if defined __BORLANDC__ && __BORLANDC__ >= 0x500
  429.         explicit complex (complex<double> _VFARC &);
  430.         explicit complex (complex<long double> _VFARC &);
  431.     #else
  432.         complex<float> (complex<double> _VFARC &);
  433.         complex<float> (complex<long double> _VFARC &);
  434.     #endif
  435.     friend complex<float> __cmf cdtocf( complex<double> cd );
  436.     friend complex<float> __cmf cetocf( complex<long double> ce );
  437.        // simple assignments: no OVERFLOW error handling
  438.     #if !defined __BORLANDC__ || __BORLANDC__ > 0x500
  439.         complex<float> _VFAR & __cmo  operator= (complex<float> _VFARC &);
  440.     #endif
  441.     complex<float> _VFAR & __cmo  operator= (complex<double> _VFARC &);
  442.     complex<float> _VFAR & __cmo  operator= (complex<long double> _VFARC &);
  443.  
  444.     // Cartesian complex from polar coordinates:
  445.     friend complex<float> __cmf polar(float _mag, float _angle=0);
  446.  
  447.     // basic operations:
  448.     float real() { return Re; }                              // real part
  449.     friend float __cmf real(complex<float> _VFARC &_z);
  450.     float imag() { return Im; }                              // imaginary part
  451.     friend float __cmf imag(complex<float> _VFARC &_z);
  452.     friend complex<float> __cmf neg(complex<float> _VFARC &); // same as unary operator -
  453.     friend complex<float> __cmf conj(complex<float> _VFARC &);// complex conjugate
  454.     friend float  __cmf norm(complex<float> _VFARC &);  // square of the magnitude
  455.     friend float  __cmf arg(complex<float>);           // angle in the plane
  456.  
  457.      // Unary operators
  458.     complex<float> _VFAR & __cmo operator+();
  459.     friend complex<float> __cmf operator-( complex<float> _VFARC &);
  460.  
  461.     // Binary operators:
  462.     friend complex<float> __cmf operator+(complex<float> _VFARC &, complex<float> _VFARC &);
  463.     friend complex<float> __cmf operator+(float, complex<float> _VFARC &);
  464.     friend complex<float> __cmf operator+(complex<float> _VFARC &, float);
  465.     friend complex<float> __cmf operator-(complex<float> _VFARC &, complex<float> _VFARC &);
  466.     friend complex<float> __cmf operator-(float, complex<float> _VFARC &);
  467.     friend complex<float> __cmf operator-(complex<float> _VFARC &, float);
  468.     friend complex<float> __cmf operator*(complex<float> _VFARC &, complex<float> _VFARC &);
  469.     friend complex<float> __cmf operator*(complex<float> _VFARC &, float);
  470.     friend complex<float> __cmf operator*(float, complex<float> _VFARC &);
  471.     friend complex<float> __cmf operator/(complex<float> _VFARC &, complex<float> _VFARC &);
  472.     friend complex<float> __cmf operator/(complex<float> _VFARC &, float);
  473.     friend complex<float> __cmf operator/(float, complex<float> _VFARC &);
  474.        // mixed-accuracy binary operators are declared at the higher-accuracy classes
  475.  
  476.     friend VBOOL __cmf operator==(complex<float> _VFARC &, complex<float> _VFARC &);
  477.     friend VBOOL __cmf operator==(complex<float> _VFARC &, float);
  478.     friend VBOOL __cmf operator!=(complex<float> _VFARC &, complex<float> _VFARC &);
  479.     friend VBOOL __cmf operator!=(complex<float> _VFARC &, float);
  480.  
  481.        //  Compound-assignment operators:
  482.     complex<float> _VFAR & __cmo  operator+= (complex<float> _VFARC &);
  483.     complex<float> _VFAR & __cmo  operator-= (complex<float> _VFARC &);
  484.     complex<float> _VFAR & __cmo  operator*= (complex<float> _VFARC &);
  485.     complex<float> _VFAR & __cmo  operator/= (complex<float> _VFARC &);
  486.  
  487.     complex<float> _VFAR & __cmo  operator+= (complex<double> _VFARC &);
  488.     complex<float> _VFAR & __cmo  operator-= (complex<double> _VFARC &);
  489.     complex<float> _VFAR & __cmo  operator*= (complex<double> _VFARC &);
  490.     complex<float> _VFAR & __cmo  operator/= (complex<double> _VFARC &);
  491.  
  492.     complex<float> _VFAR & __cmo  operator+= (complex<long double> _VFARC &);
  493.     complex<float> _VFAR & __cmo  operator-= (complex<long double> _VFARC &);
  494.     complex<float> _VFAR & __cmo  operator*= (complex<long double> _VFARC &);
  495.     complex<float> _VFAR & __cmo  operator/= (complex<long double> _VFARC &);
  496.  
  497.     // Overloaded ANSI C math functions
  498.     friend float          __cmf abs(complex<float>);
  499.     friend complex<float> __cmf acos(complex<float>);
  500.     friend complex<float> __cmf asin(complex<float>);
  501.     friend complex<float> __cmf atan(complex<float>);
  502.     friend complex<float> __cmf cos(complex<float>);
  503.     friend complex<float> __cmf cosh(complex<float>);
  504.     friend complex<float> __cmf cubic(complex<float>);  // raise to the third power
  505.     friend complex<float> __cmf exp(complex<float>);
  506.     friend complex<float> __cmf inv(complex<float>);    //   1.0 / z
  507.     friend complex<float> __cmf ipow(complex<float> __base, int __expon);  // integer power
  508.     friend complex<float> __cmf ln(complex<float>);
  509.     friend complex<float> __cmf log(complex<float>); // same as ln
  510.     friend complex<float> __cmf log2(complex<float>);
  511.     friend complex<float> __cmf log10(complex<float>);
  512.     friend complex<float> __cmf pow(complex<float> __base, float __expon);
  513.     friend complex<float> __cmf powReExpo(complex<float> __base, float __expon);
  514.     friend complex<float> __cmf pow(float __base, complex<float> __expon);
  515.     friend complex<float> __cmf powReBase(float __base, complex<float> __expon);
  516.     friend complex<float> __cmf pow(complex<float> __base, complex<float> __expon);
  517.     friend complex<float> __cmf quartic(complex<float>);  // raise to the fourth power
  518.     friend complex<float> __cmf sin(complex<float>);
  519.     friend complex<float> __cmf sinh(complex<float>);
  520.     friend complex<float> __cmf sqrt(complex<float>);
  521.     friend complex<float> __cmf square(complex<float>);
  522.     friend complex<float> __cmf tan(complex<float>);
  523.     friend complex<float> __cmf tanh(complex<float>);
  524.  
  525.     friend istream _VFAR & __cmf operator>> (istream _VFAR &, complex<float> _VFAR &);
  526.     friend ostream _VFAR & __cmf operator<< (ostream _VFAR &, complex<float> _VFARC &);
  527.  
  528.     float Re, Im;  // still public!
  529. };
  530.  
  531. class  complex<double>
  532. {
  533.   public:
  534.          // constructors:
  535.     #if defined __BORLANDC__ && __BORLANDC__ >= 0x450
  536.         complex( double Re_part, double Im_part ) {Re=Re_part; Im=Im_part;}
  537.         complex( double Re_part )  {Re=Re_part; Im=0;}
  538.         complex() {};
  539.             // interconversions between the three levels of accuracy:
  540.             // with OVERFLOW error handling for the down-conversions
  541.         complex (complex<float> _VFARC &);
  542.     #else // problems with the template definitions in older versions
  543.           complex<double>( double Re_part, double Im_part ) {Re=Re_part; Im=Im_part;}
  544.           complex<double>( double Re_part )  {Re=Re_part; Im=0;}
  545.           complex<double>() {};
  546.           complex<double> (complex<float> _VFARC &);
  547.     #endif
  548.     #if !defined __BORLANDC__ || __BORLANDC__ > 0x500
  549.         complex<double> (complex<double> _VFARC &);
  550.     #endif
  551.     #if defined __BORLANDC__ && __BORLANDC__ >= 0x500
  552.         explicit complex (complex<long double> _VFARC &);
  553.     #else
  554.         complex<double> (complex<long double> _VFARC &);
  555.     #endif
  556.     friend complex<double> __cmf cetocd( complex<long double> ce );
  557.           // simple assignments: no OVERFLOW error handling
  558.     complex<double> _VFAR & __cmo  operator= (complex<float> _VFARC &);
  559.     #if !defined __BORLANDC__ || __BORLANDC__ > 0x500
  560.         complex<double> _VFAR & __cmo  operator= (complex<double> _VFARC &);
  561.     #endif
  562.     complex<double> _VFAR & __cmo  operator= (complex<long double> _VFARC &);
  563.  
  564.     // Cartesian complex from polar coordinates:
  565.     friend complex<double> __cmf polar(double __mag, double __angle=0);
  566.  
  567.     // basic operations:
  568.     double real() { return Re; }                              // real part
  569.     friend double __cmf real(complex<double> _VFARC &_z);
  570.     double imag() { return Im; }                              // imaginary part
  571.     friend double __cmf imag(complex<double> _VFARC &_z);
  572.     friend complex<double> __cmf neg(complex<double> _VFARC &); // same as unary operator -
  573.     friend complex<double> __cmf conj(complex<double> _VFARC &);// complex conjugate
  574.     friend double  __cmf norm(complex<double> _VFARC &);  // square of the magnitude
  575.     friend double  __cmf arg(complex<double>);          // the angle in the plane
  576.  
  577.      // Unary operators
  578.     complex<double> _VFAR & __cmo operator+();
  579.     friend complex<double>  __cmf operator-( complex<double> _VFARC &);
  580.  
  581.         // Binary operators:
  582.     friend complex<double> __cmf operator+(complex<double> _VFARC &, complex<double> _VFARC &);
  583.     friend complex<double> __cmf operator+(double, complex<double> _VFARC &);
  584.     friend complex<double> __cmf operator+(complex<double> _VFARC &, double);
  585.     friend complex<double> __cmf operator-(complex<double> _VFARC &, complex<double> _VFARC &);
  586.     friend complex<double> __cmf operator-(double, complex<double> _VFARC &);
  587.     friend complex<double> __cmf operator-(complex<double> _VFARC &, double);
  588.     friend complex<double> __cmf operator*(complex<double> _VFARC &, complex<double> _VFARC &);
  589.     friend complex<double> __cmf operator*(complex<double> _VFARC &, double);
  590.     friend complex<double> __cmf operator*(double, complex<double> _VFARC &);
  591.     friend complex<double> __cmf operator/(complex<double> _VFARC &, complex<double> _VFARC &);
  592.     friend complex<double> __cmf operator/(complex<double> _VFARC &, double);
  593.     friend complex<double> __cmf operator/(double, complex<double> _VFARC &);
  594.         // float-double mixed-accuracy versions:
  595.     friend complex<double> __cmf operator+(complex<float> _VFARC &, complex<double> _VFARC &);
  596.     friend complex<double> __cmf operator+(complex<double> _VFARC &, complex<float> _VFARC &);
  597.     friend complex<double> __cmf operator-(complex<float> _VFARC &, complex<double> _VFARC &);
  598.     friend complex<double> __cmf operator-(complex<double> _VFARC &, complex<float> _VFARC &);
  599.     friend complex<double> __cmf operator*(complex<float> _VFARC &, complex<double> _VFARC &);
  600.     friend complex<double> __cmf operator*(complex<double> _VFARC &, complex<float> _VFARC &);
  601.     friend complex<double> __cmf operator/(complex<float> _VFARC &, complex<double> _VFARC &);
  602.     friend complex<double> __cmf operator/(complex<double> _VFARC &, complex<float> _VFARC &);
  603.  
  604.     friend VBOOL __cmf operator==(complex<double> _VFARC &, complex<double> _VFARC &);
  605.     friend VBOOL __cmf operator==(complex<double> _VFARC &, double);
  606.     friend VBOOL __cmf operator!=(complex<double> _VFARC &, complex<double> _VFARC &);
  607.     friend VBOOL __cmf operator!=(complex<double> _VFARC &, double);
  608.  
  609.        //  Compound-assignment operators:
  610.     complex<double> _VFAR & __cmo  operator+= (complex<float> _VFARC &);
  611.     complex<double> _VFAR & __cmo  operator-= (complex<float> _VFARC &);
  612.     complex<double> _VFAR & __cmo  operator*= (complex<float> _VFARC &);
  613.     complex<double> _VFAR & __cmo  operator/= (complex<float> _VFARC &);
  614.  
  615.     complex<double> _VFAR & __cmo  operator+= (complex<double> _VFARC &);
  616.     complex<double> _VFAR & __cmo  operator-= (complex<double> _VFARC &);
  617.     complex<double> _VFAR & __cmo  operator*= (complex<double> _VFARC &);
  618.     complex<double> _VFAR & __cmo  operator/= (complex<double> _VFARC &);
  619.  
  620.     complex<double> _VFAR & __cmo  operator+= (complex<long double> _VFARC &);
  621.     complex<double> _VFAR & __cmo  operator-= (complex<long double> _VFARC &);
  622.     complex<double> _VFAR & __cmo  operator*= (complex<long double> _VFARC &);
  623.     complex<double> _VFAR & __cmo  operator/= (complex<long double> _VFARC &);
  624.  
  625.     // Overloaded ANSI C math functions
  626.     friend double          __cmf abs(complex<double>);
  627.     friend complex<double> __cmf acos(complex<double>);
  628.     friend complex<double> __cmf asin(complex<double>);
  629.     friend complex<double> __cmf atan(complex<double>);
  630.     friend complex<double> __cmf cos(complex<double>);
  631.     friend complex<double> __cmf cosh(complex<double>);
  632.     friend complex<double> __cmf cubic(complex<double>);  // raise to the third power
  633.     friend complex<double> __cmf exp(complex<double>);
  634.     friend complex<double> __cmf inv(complex<double>);    //   1.0 / z
  635.     friend complex<double> __cmf ipow(complex<double> __base, int __expon);  // integer power
  636.     friend complex<double> __cmf ln(complex<double>);
  637.     friend complex<double> __cmf log(complex<double>); // same as ln
  638.     friend complex<double> __cmf log2(complex<double>);
  639.     friend complex<double> __cmf log10(complex<double>);
  640.     friend complex<double> __cmf pow(complex<double> __base, double __expon);
  641.     friend complex<double> __cmf powReExpo(complex<double> __base, double __expon);
  642.     friend complex<double> __cmf pow(double __base, complex<double> __expon);
  643.     friend complex<double> __cmf powReBase(double __base, complex<double> __expon);
  644.     friend complex<double> __cmf pow(complex<double> __base, complex<double> __expon);
  645.     friend complex<double> __cmf quartic(complex<double>);  // raise to the fourth power
  646.     friend complex<double> __cmf sin(complex<double>);
  647.     friend complex<double> __cmf sinh(complex<double>);
  648.     friend complex<double> __cmf sqrt(complex<double>);
  649.     friend complex<double> __cmf square(complex<double>);
  650.     friend complex<double> __cmf tan(complex<double>);
  651.     friend complex<double> __cmf tanh(complex<double>);
  652.  
  653.     friend istream _VFAR & __cmf operator>> (istream _VFAR &, complex<double> _VFAR &);
  654.     friend ostream _VFAR & __cmf operator<< (ostream _VFAR &, complex<double> _VFARC &);
  655.  
  656.     double Re, Im;  // still public!
  657. };
  658.  
  659. class complex<long double>
  660. {
  661.   public:
  662.          // constructors:
  663.     #if defined __BORLANDC__ && __BORLANDC__ >= 0x450
  664.         complex( long double Re_part, long double Im_part ) {Re=Re_part; Im=Im_part;}
  665.         complex( long double Re_part )  {Re=Re_part; Im=0;}
  666.         complex() {};
  667.             // interconversions between the three levels of accuracy:
  668.         complex (complex<float> _VFARC &);
  669.         complex (complex<double> _VFARC &);
  670.      #else // problems with the template definitions in older versions
  671.         complex<long double>( long double Re_part, long double Im_part ) {Re=Re_part; Im=Im_part;}
  672.         complex<long double>( long double Re_part )  {Re=Re_part; Im=0;}
  673.         complex<long double>() {};
  674.                 // interconversions between the three levels of accuracy:
  675.         complex<long double> (complex<float> _VFARC &);
  676.         complex<long double> (complex<double> _VFARC &);
  677.     #endif
  678.     #if !defined __BORLANDC__ || __BORLANDC__ > 0x500
  679.         complex<long double> (complex<long double> _VFARC &);
  680.     #endif
  681.           // simple assignments do the same:
  682.     complex<long double> _VFAR & __cmo  operator=  (complex<float> _VFARC &);
  683.     complex<long double> _VFAR & __cmo  operator=  (complex<double> _VFARC &);
  684.     #if !defined __BORLANDC__ || __BORLANDC__ > 0x500
  685.         complex<long double> _VFAR & __cmo  operator=  (complex<long double> _VFARC &);
  686.     #endif
  687.  
  688.           // Cartesian complex from polar coordinates:
  689.     friend complex<long double> __cmf polar(long double __mag, long double __angle=0);
  690.         // basic operations:
  691.     long double real() { return Re; }                              // real part
  692.     friend long double __cmf real(complex<long double> _VFARC &_z);
  693.     long double imag() { return Im; }                              // imaginary part
  694.     friend long double __cmf imag(complex<long double> _VFARC &_z);
  695.     friend complex<long double> __cmf neg(complex<long double> _VFARC &); // same as unary operator -
  696.     friend complex<long double> __cmf conj(complex<long double> _VFARC &);// complex conjugate
  697.     friend long double  __cmf norm(complex<long double> _VFARC &);  // square of the magnitude
  698.     friend long double  __cmf arg(complex<long double>);          // the angle in the plane
  699.  
  700.      // Unary operators
  701.     complex<long double> _VFAR & __cmo operator+();
  702.     friend complex<long double>  __cmf operator-( complex<long double> _VFARC &);
  703.  
  704.         // Binary operators:
  705.     friend complex<long double> __cmf operator+(complex<long double> _VFARC &, complex<long double> _VFARC &);
  706.     friend complex<long double> __cmf operator+(long double, complex<long double> _VFARC &);
  707.     friend complex<long double> __cmf operator+(complex<long double> _VFARC &, long double);
  708.     friend complex<long double> __cmf operator-(complex<long double> _VFARC &, complex<long double> _VFARC &);
  709.     friend complex<long double> __cmf operator-(long double, complex<long double> _VFARC &);
  710.     friend complex<long double> __cmf operator-(complex<long double> _VFARC &, long double);
  711.     friend complex<long double> __cmf operator*(complex<long double> _VFARC &, complex<long double> _VFARC &);
  712.     friend complex<long double> __cmf operator*(complex<long double> _VFARC &, long double);
  713.     friend complex<long double> __cmf operator*(long double, complex<long double> _VFARC &);
  714.     friend complex<long double> __cmf operator/(complex<long double> _VFARC & __dividend,
  715.                                                 complex<long double> _VFARC & __divisor);
  716.     friend complex<long double> __cmf operator/(complex<long double> _VFARC &, long double );
  717.     friend complex<long double> __cmf operator/(long double __dividend,
  718.                                                 complex<long double> _VFARC &__divisor);
  719.         // mixed-accuracy versions:
  720.     friend complex<long double> __cmf operator+(complex<float> _VFARC &, complex<long double> _VFARC &);
  721.     friend complex<long double> __cmf operator+(complex<long double> _VFARC &, complex<float> _VFARC &);
  722.     friend complex<long double> __cmf operator+(complex<double> _VFARC &, complex<long double> _VFARC &);
  723.     friend complex<long double> __cmf operator+(complex<long double> _VFARC &, complex<double> _VFARC &);
  724.     friend complex<long double> __cmf operator-(complex<float> _VFARC &, complex<long double> _VFARC &);
  725.     friend complex<long double> __cmf operator-(complex<long double> _VFARC &, complex<float> _VFARC &);
  726.     friend complex<long double> __cmf operator-(complex<double> _VFARC &, complex<long double> _VFARC &);
  727.     friend complex<long double> __cmf operator-(complex<long double> _VFARC &, complex<double> _VFARC &);
  728.     friend complex<long double> __cmf operator*(complex<float> _VFARC &, complex<long double> _VFARC &);
  729.     friend complex<long double> __cmf operator*(complex<long double> _VFARC &, complex<float> _VFARC &);
  730.     friend complex<long double> __cmf operator*(complex<double> _VFARC &, complex<long double> _VFARC &);
  731.     friend complex<long double> __cmf operator*(complex<long double> _VFARC &, complex<double> _VFARC &);
  732.     friend complex<long double> __cmf operator/(complex<long double> _VFARC & __dividend,
  733.                                                 complex<float> _VFARC & __divisor);
  734.     friend complex<long double> __cmf operator/(complex<long double> _VFARC & __dividend,
  735.                                                 complex<double> _VFARC & __divisor);
  736.         // no explicit version for mixed division involving complex<long double>
  737.         // as the divisor; rely on implicit conversion of the dividend and use
  738.         // the operator /( complex<long double>, complex<long double> ).
  739.  
  740.     friend VBOOL __cmf operator==(complex<long double> _VFARC &, complex<long double> _VFARC &);
  741.     friend VBOOL __cmf operator==(complex<long double> _VFARC &, long double);
  742.     friend VBOOL __cmf operator!=(complex<long double> _VFARC &, complex<long double> _VFARC &);
  743.     friend VBOOL __cmf operator!=(complex<long double> _VFARC &, long double);
  744.  
  745.        //  Compound-assignment operators:
  746.     complex<long double> _VFAR & __cmo  operator+= (complex<float> _VFARC &);
  747.     complex<long double> _VFAR & __cmo  operator-= (complex<float> _VFARC &);
  748.     complex<long double> _VFAR & __cmo  operator*= (complex<float> _VFARC &);
  749.     complex<long double> _VFAR & __cmo  operator/= (complex<float> _VFARC &);
  750.  
  751.     complex<long double> _VFAR & __cmo  operator+= (complex<double> _VFARC &);
  752.     complex<long double> _VFAR & __cmo  operator-= (complex<double> _VFARC &);
  753.     complex<long double> _VFAR & __cmo  operator*= (complex<double> _VFARC &);
  754.     complex<long double> _VFAR & __cmo  operator/= (complex<double> _VFARC &);
  755.  
  756.     complex<long double> _VFAR & __cmo  operator+= (complex<long double> _VFARC &);
  757.     complex<long double> _VFAR & __cmo  operator-= (complex<long double> _VFARC &);
  758.     complex<long double> _VFAR & __cmo  operator*= (complex<long double> _VFARC &);
  759.     complex<long double> _VFAR & __cmo  operator/= (complex<long double> _VFARC &);
  760.  
  761.     // Overloaded ANSI C math functions
  762.     friend long double          __cmf abs(complex<long double>);
  763.     friend complex<long double> __cmf acos(complex<long double>);
  764.     friend complex<long double> __cmf asin(complex<long double>);
  765.     friend complex<long double> __cmf atan(complex<long double>);
  766.     friend complex<long double> __cmf cos(complex<long double>);
  767.     friend complex<long double> __cmf cosh(complex<long double>);
  768.     friend complex<long double> __cmf cubic(complex<long double>);  // raise to the third power
  769.     friend complex<long double> __cmf exp(complex<long double>);
  770.     friend complex<long double> __cmf inv(complex<long double>);    //   1.0 / z
  771.     friend complex<long double> __cmf ipow(complex<long double> __base, int __expon);  // integer power
  772.     friend complex<long double> __cmf ln(complex<long double>);
  773.     friend complex<long double> __cmf log(complex<long double>); // same as ln
  774.     friend complex<long double> __cmf log2(complex<long double>);
  775.     friend complex<long double> __cmf log10(complex<long double>);
  776.     friend complex<long double> __cmf pow(complex<long double> __base, long double __expon);
  777.     friend complex<long double> __cmf powReExpo(complex<long double> __base, long double __expon);
  778.     friend complex<long double> __cmf pow(long double __base, complex<long double> __expon);
  779.     friend complex<long double> __cmf powReBase(long double __base, complex<long double> __expon);
  780.     friend complex<long double> __cmf pow(complex<long double> __base, complex<long double> __expon);
  781.     friend complex<long double> __cmf quartic(complex<long double>);  // raise to the fourth power
  782.     friend complex<long double> __cmf sin(complex<long double>);
  783.     friend complex<long double> __cmf sinh(complex<long double>);
  784.     friend complex<long double> __cmf sqrt(complex<long double>);
  785.     friend complex<long double> __cmf square(complex<long double>);
  786.     friend complex<long double> __cmf tan(complex<long double>);
  787.     friend complex<long double> __cmf tanh(complex<long double>);
  788.  
  789.     friend istream _VFAR & __cmf operator>> (istream _VFAR &,
  790.                                              complex<long double> _VFAR &);
  791.     friend ostream _VFAR & __cmf operator<< (ostream _VFAR &,
  792.                                              complex<long double> _VFARC &);
  793.     long double Re, Im; // still public!
  794. };
  795. #ifndef _CMATH_DEFS
  796.     typedef long double extended;
  797.     typedef complex<float>      fComplex;
  798.     typedef complex<double>     dComplex;
  799.     typedef complex<extended>   eComplex;
  800.     #define _CMATH_DEFS
  801. #endif  // _CMATH_DEFS
  802.  
  803. // inline-implementation of the simple functions and operators
  804.  
  805. //  data-type interconverting constructors:
  806. //  in the down-conversions, OVERFLOW errors are handled via _matherr
  807. inline complex<float>::complex (complex<double> _VFARC & zd){ *this = cdtocf( zd ); }
  808. inline complex<float>::complex (complex<long double> _VFARC & ze){*this = cetocf( ze );}
  809. inline complex<double>::complex (complex<float> _VFARC & zf){Re = zf.Re; Im = zf.Im; }
  810. inline complex<double>::complex (complex<long double> _VFARC & ze){*this = cetocd( ze );}
  811. inline complex<long double>::complex (complex<float> _VFARC & zf){Re=zf.Re; Im=zf.Im;}
  812. inline complex<long double>::complex (complex<double> _VFARC & zd){Re=zd.Re; Im=zd.Im;}
  813. #if !defined __BORLANDC__ || __BORLANDC__ > 0x500
  814.     inline complex<float>::complex (complex<float> _VFARC & zf){ Re = zf.Re; Im = zf.Im;}
  815.     inline complex<double>::complex (complex<double> _VFARC & zd){Re = zd.Re; Im = zd.Im; }
  816.     inline complex<long double>::complex (complex<long double> _VFARC & ze){Re=ze.Re; Im=ze.Im;}
  817. #endif
  818.  
  819. //  simple assignments:
  820. inline complex<float> _VFAR & complex<float>::operator= (complex<double> _VFARC & __z)
  821. {   Re = __z.Re; Im = __z.Im; return *this; }
  822. inline complex<float> _VFAR & complex<float>::operator= (complex<long double> _VFARC & __z)
  823. {   Re = __z.Re; Im = __z.Im; return *this; }
  824. inline complex<double> _VFAR & complex<double>::operator= (complex<float> _VFARC & __z)
  825. {   Re = __z.Re; Im = __z.Im; return *this; }
  826. inline complex<double> _VFAR & complex<double>::operator= (complex<long double> _VFARC & __z)
  827. {   Re = __z.Re; Im = __z.Im; return *this; }
  828. inline complex<long double> _VFAR & complex<long double>::operator= (complex<float> _VFARC & __z)
  829. {   Re = __z.Re; Im = __z.Im; return *this; }
  830. inline complex<long double> _VFAR & complex<long double>::operator= (complex<double> _VFARC & __z)
  831. {   Re = __z.Re; Im = __z.Im; return *this; }
  832. #if !defined __BORLANDC__ || __BORLANDC__ > 0x500
  833.     inline complex<float> _VFAR & __cmo complex<float>::operator= (complex<float> _VFARC & __z)
  834.     {   Re = __z.Re; Im = __z.Im; return *this; }
  835.     inline complex<double> _VFAR & complex<double>::operator= (complex<double> _VFARC & __z)
  836.     {   Re = __z.Re; Im = __z.Im; return *this; }
  837.     inline complex<long double> _VFAR & complex<long double>::operator= (complex<long double> _VFARC & __z)
  838.     {   Re = __z.Re; Im = __z.Im; return *this; }
  839. #endif
  840.  
  841. // basic operations:
  842. template<class T>
  843. inline T __cmf real( complex<T> _VFARC & __z) { return __z.Re; }
  844.  
  845. template<class T>
  846. inline T __cmf imag( complex<T> _VFARC & __z) { return __z.Im; }
  847.  
  848. template <class T>
  849. inline complex<T> __cmf neg( complex<T> _VFARC & __z )
  850. {   return complex<T>(-__z.Re, -__z.Im); }
  851.  
  852. template <class T>
  853. inline complex<T> __cmf conj( complex<T> _VFARC & __z )
  854. {   return complex<T>(__z.Re, -__z.Im); }
  855.  
  856. template <class T>
  857. inline T __cmf norm( complex<T> _VFARC & __z )
  858. {   return __z.Re*__z.Re + __z.Im*__z.Im; }
  859.  
  860.          // Unary operators:
  861. template <class T>
  862. inline complex<T> _VFAR & __cmo complex<T>::operator+()
  863. {   return (*this); }
  864.  
  865. template <class T>
  866. inline complex<T> __cmf operator-( complex<T> _VFARC & __z)
  867. {   return complex<T>(-__z.Re, -__z.Im); }
  868.  
  869.         // Binary operators:
  870. template <class T>
  871. inline complex<T> __cmf operator+( complex<T> _VFARC & __z1, complex<T> _VFARC & __z2)
  872. {   return complex<T>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  873.  
  874. template <class T>
  875. inline complex<T> __cmf operator+( complex<T> _VFARC & __z1, T __z2Re )
  876. {   return complex<T>(__z1.Re+__z2Re, __z1.Im); }
  877.  
  878. template <class T>
  879. inline complex<T> __cmf operator+( T __z1Re, complex<T> _VFARC & __z2 )
  880. {   return complex<T>(__z1Re + __z2.Re, __z2.Im); }
  881.  
  882. template <class T>
  883. inline complex<T> __cmf operator-( complex<T> _VFARC & __z1, complex<T> _VFARC & __z2 )
  884. {   return complex<T>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  885.  
  886. template <class T>
  887. inline complex<T> __cmf operator-( complex<T> _VFARC & __z1, T __z2Re )
  888. {   return complex<T>(__z1.Re - __z2Re, __z1.Im); }
  889.  
  890. template <class T>
  891. inline complex<T> __cmf operator-( T __z1Re, complex<T> _VFARC & __z2 )
  892. {   return complex<T>(__z1Re - __z2.Re, -__z2.Im); }
  893.  
  894. template <class T>
  895. inline complex<T> __cmf operator*( complex<T> _VFARC & __z1, complex<T> _VFARC & __z2)
  896. {   return complex<T>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  897.                        __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  898. }
  899. template <class T>
  900. inline complex<T> __cmf operator*( complex<T> _VFARC & __z1, T __z2Re )
  901. {   return complex<T>( __z1.Re * __z2Re, __z1.Im * __z2Re ); }
  902.  
  903. template <class T>
  904. inline complex<T> __cmf operator*( T __z1Re, complex<T> _VFARC & __z2 )
  905. {   return complex<T>( __z1Re * __z2.Re, __z1Re * __z2.Im ); }
  906.  
  907. template <class T>
  908. inline complex<T> __cmf operator/( complex<T> _VFARC & __dividend, T __divisorRe)
  909. {   return complex<T>( __dividend.Re / __divisorRe, __dividend.Im / __divisorRe ); }
  910.  
  911. inline complex<float> __cmf operator/( complex<float> _VFARC & __dividend,
  912.                                        complex<float> _VFARC & __divisor )
  913. {     complex<float> Result;
  914.       double denom;
  915.       Result.Re = (float)((__dividend.Re *__divisor.Re +
  916.                            __dividend.Im *__divisor.Im) /
  917.          (denom = (double)(__divisor.Re) * __divisor.Re +
  918.                   (double)(__divisor.Im) * __divisor.Im));
  919.       Result.Im = (float)((__dividend.Im * __divisor.Re -
  920.                            __dividend.Re * __divisor.Im ) / denom);
  921.       return Result;
  922. }
  923.  
  924. inline complex<double> __cmf operator/( complex<double> _VFARC & __dividend,
  925.                                         complex<double> _VFARC & __divisor )
  926. {     complex<double> Result;
  927.       long double denom;
  928.       Result.Re = (double)((__dividend.Re *__divisor.Re +
  929.                             __dividend.Im *__divisor.Im) /
  930.          (denom = (long double)(__divisor.Re) * __divisor.Re +
  931.                   (long double)(__divisor.Im) * __divisor.Im));
  932.       Result.Im = (double)((__dividend.Im * __divisor.Re -
  933.                             __dividend.Re * __divisor.Im ) / denom);
  934.       return Result;
  935. }
  936.     //   operator / (complex<long double>, complex<long double> )
  937.     //   cannot safely be inlined
  938.  
  939. inline complex<float> __cmf operator /( float __dividendRe,
  940.                                         complex<float> _VFARC & __divisor )
  941. {     complex<float> Result;
  942.       double         denom;
  943.       Result.Re = (float)((__dividendRe * __divisor.Re) /
  944.         (denom = (double)(__divisor.Re) * __divisor.Re +
  945.                  (double)(__divisor.Im) * __divisor.Im));
  946.       Result.Im = -(float)((__dividendRe * __divisor.Im ) / denom);
  947.       return Result;
  948. }
  949.  
  950. inline complex<double> __cmf operator /(double __dividendRe,
  951.                                         complex<double> _VFARC & __divisor )
  952. {     complex<double> Result;
  953.       long double     denom;
  954.       Result.Re = (double)((__dividendRe * __divisor.Re) /
  955.         (denom = (long double)(__divisor.Re) * __divisor.Re +
  956.                  (long double)(__divisor.Im) * __divisor.Im));
  957.       Result.Im = -(double)((__dividendRe * __divisor.Im ) / denom);
  958.       return Result;
  959. }
  960.     //   operator / (long double, complex<long double> )
  961.     //   cannot safely be inlined
  962.  
  963.     // Mixed-accuracy level binary operators:
  964. inline complex<double> __cmf operator+( complex<float> _VFARC & __z1, complex<double> _VFARC & __z2)
  965. {   return complex<double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  966. inline complex<double> __cmf operator+( complex<double> _VFARC & __z1, complex<float> _VFARC & __z2)
  967. {   return complex<double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  968. inline complex<long double> __cmf operator+( complex<float> _VFARC & __z1, complex<long double> _VFARC & __z2)
  969. {   return complex<long double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  970. inline complex<long double> __cmf operator+( complex<long double> _VFARC & __z1, complex<float> _VFARC & __z2)
  971. {   return complex<long double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  972. inline complex<long double> __cmf operator+( complex<double> _VFARC & __z1, complex<long double> _VFARC & __z2)
  973. {   return complex<long double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  974. inline complex<long double> __cmf operator+( complex<long double> _VFARC & __z1, complex<double> _VFARC & __z2)
  975. {   return complex<long double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  976.  
  977. inline complex<double> __cmf operator-( complex<float> _VFARC & __z1, complex<double> _VFARC & __z2)
  978. {   return complex<double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  979. inline complex<double> __cmf operator-( complex<double> _VFARC & __z1, complex<float> _VFARC & __z2)
  980. {   return complex<double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  981. inline complex<long double> __cmf operator-( complex<float> _VFARC & __z1, complex<long double> _VFARC & __z2)
  982. {   return complex<long double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  983. inline complex<long double> __cmf operator-( complex<long double> _VFARC & __z1, complex<float> _VFARC & __z2)
  984. {   return complex<long double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  985. inline complex<long double> __cmf operator-( complex<double> _VFARC & __z1, complex<long double> _VFARC & __z2)
  986. {   return complex<long double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  987. inline complex<long double> __cmf operator-( complex<long double> _VFARC & __z1, complex<double> _VFARC & __z2)
  988. {   return complex<long double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  989.  
  990. inline complex<double> __cmf operator*( complex<float> _VFARC & __z1, complex<double> _VFARC & __z2 )
  991. {   return complex<double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  992.                             __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  993. }
  994. inline complex<double> __cmf operator*( complex<double> _VFARC & __z1, complex<float> _VFARC & __z2 )
  995. {   return complex<double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  996.                             __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  997. }
  998. inline complex<long double> __cmf operator*( complex<float> _VFARC & __z1, complex<long double> _VFARC & __z2 )
  999. {   return complex<long double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  1000.                                  __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  1001. }
  1002. inline complex<long double> __cmf operator*( complex<long double> _VFARC & __z1, complex<float> _VFARC & __z2 )
  1003. {   return complex<long double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  1004.                                  __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  1005. }
  1006. inline complex<long double> __cmf operator*( complex<double> _VFARC & __z1, complex<long double> _VFARC & __z2 )
  1007. {   return complex<long double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  1008.                                  __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  1009. }
  1010. inline complex<long double> __cmf operator*( complex<long double> _VFARC & __z1, complex<double> _VFARC & __z2 )
  1011. {   return complex<long double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  1012.                                  __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  1013. }
  1014.  
  1015. inline complex<double> __cmf operator/( complex<float> _VFARC & __dividend,
  1016.                                         complex<double> _VFARC & __divisor )
  1017. {     complex<double> Result;
  1018.       long double     denom;
  1019.       Result.Re = (double)((__dividend.Re *__divisor.Re +
  1020.                             __dividend.Im *__divisor.Im) /
  1021.          (denom = (long double)(__divisor.Re) * __divisor.Re +
  1022.                   (long double)(__divisor.Im) * __divisor.Im));
  1023.       Result.Im = (double)((__dividend.Im * __divisor.Re -
  1024.                             __dividend.Re * __divisor.Im ) / denom);
  1025.       return Result;
  1026. }
  1027.  
  1028. inline complex<double> __cmf operator/( complex<double> _VFARC & __dividend,
  1029.                                         complex<float>  _VFARC & __divisor )
  1030. {     complex<double> Result;
  1031.       double          denom;
  1032.       Result.Re = (__dividend.Re *__divisor.Re +
  1033.                    __dividend.Im *__divisor.Im) /
  1034.          (denom = (double)(__divisor.Re) * __divisor.Re +
  1035.                   (double)(__divisor.Im) * __divisor.Im);
  1036.       Result.Im = (__dividend.Im * __divisor.Re -
  1037.                    __dividend.Re * __divisor.Im ) / denom;
  1038.       return Result;
  1039. }
  1040.  
  1041. inline complex<long double> __cmf operator/( complex<long double> _VFARC & __dividend,
  1042.                                              complex<float>  _VFARC & __divisor )
  1043. {     complex<long double> Result;
  1044.       double               denom;
  1045.       Result.Re = (__dividend.Re *__divisor.Re +
  1046.                    __dividend.Im *__divisor.Im) /
  1047.          (denom = (double)(__divisor.Re) * __divisor.Re +
  1048.                   (double)(__divisor.Im) * __divisor.Im);
  1049.       Result.Im = (__dividend.Im * __divisor.Re -
  1050.                    __dividend.Re * __divisor.Im ) / denom;
  1051.       return Result;
  1052. }
  1053.  
  1054. inline complex<long double> __cmf operator/( complex<long double> _VFARC & __dividend,
  1055.                                              complex<double>  _VFARC & __divisor )
  1056. {     complex<long double> Result;
  1057.       long double          denom;
  1058.       Result.Re = (__dividend.Re *__divisor.Re +
  1059.                    __dividend.Im *__divisor.Im) /
  1060.          (denom = (long double)(__divisor.Re) * __divisor.Re +
  1061.                   (long double)(__divisor.Im) * __divisor.Im);
  1062.       Result.Im = (__dividend.Im * __divisor.Re -
  1063.                    __dividend.Re * __divisor.Im ) / denom;
  1064.       return Result;
  1065. }
  1066.  
  1067. template <class T>
  1068. inline VBOOL __cmf operator== (complex<T> _VFARC & __z1, complex<T> _VFARC & __z2)
  1069. {   return __z1.Re == __z2.Re && __z1.Im == __z2.Im; }
  1070.  
  1071. template <class T>
  1072. inline VBOOL __cmf operator== (T __z1Re, complex<T> _VFARC & __z2)
  1073. {   return __z1Re == __z2.Re && __z2.Im == 0; }
  1074.  
  1075. template <class T>
  1076. inline VBOOL __cmf operator== (complex<T> _VFARC & __z1, T __z2Re)
  1077. {   return __z1.Re == __z2Re && __z1.Im == 0; }
  1078.  
  1079. template <class T>
  1080. inline VBOOL __cmf operator!= (complex<T> _VFARC & __z1, complex<T> _VFARC & __z2)
  1081. {   return __z1.Re != __z2.Re || __z1.Im != __z2.Im; }
  1082.  
  1083. template <class T>
  1084. inline VBOOL __cmf operator!= (T __z1Re, complex<T> _VFARC & __z2)
  1085. {   return __z1Re != __z2.Re || __z2.Im != 0; }
  1086.  
  1087. template <class T>
  1088. inline VBOOL __cmf operator!= (complex<T> _VFARC & __z1, T __z2Re)
  1089. {   return __z1.Re != __z2Re || __z1.Im != 0; }
  1090.  
  1091.       // Compound-assignment operators:
  1092. inline complex<float> _VFAR & __cmo complex<float>::operator+= (complex<float> _VFARC & __s2)
  1093. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1094.  
  1095. inline complex<float> _VFAR & __cmo complex<float>::operator+= (complex<double> _VFARC & __s2)
  1096. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1097.  
  1098. inline complex<float> _VFAR & __cmo complex<float>::operator+= (complex<long double> _VFARC & __s2)
  1099. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1100.  
  1101. inline complex<double> _VFAR & __cmo complex<double>::operator+= (complex<float> _VFARC & __s2)
  1102. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1103.  
  1104. inline complex<double> _VFAR & __cmo complex<double>::operator+= (complex<double> _VFARC & __s2)
  1105. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1106.  
  1107. inline complex<double> _VFAR & __cmo complex<double>::operator+= (complex<long double> _VFARC & __s2)
  1108. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1109.  
  1110. inline complex<long double> _VFAR & __cmo complex<long double>::operator+= (complex<float> _VFARC & __s2)
  1111. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1112.  
  1113. inline complex<long double> _VFAR & __cmo complex<long double>::operator+= (complex<double> _VFARC & __s2)
  1114. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1115.  
  1116. inline complex<long double> _VFAR & __cmo complex<long double>::operator+= (complex<long double> _VFARC & __s2)
  1117. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1118.  
  1119. inline complex<float> _VFAR & __cmo complex<float>::operator-= (complex<float> _VFARC & __s2)
  1120. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1121.  
  1122. inline complex<float> _VFAR & __cmo complex<float>::operator-= (complex<double> _VFARC & __s2)
  1123. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1124.  
  1125. inline complex<float> _VFAR & __cmo complex<float>::operator-= (complex<long double> _VFARC & __s2)
  1126. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1127.  
  1128. inline complex<double> _VFAR & __cmo complex<double>::operator-= (complex<float> _VFARC & __s2)
  1129. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1130.  
  1131. inline complex<double> _VFAR & __cmo complex<double>::operator-= (complex<double> _VFARC & __s2)
  1132. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1133.  
  1134. inline complex<double> _VFAR & __cmo complex<double>::operator-= (complex<long double> _VFARC & __s2)
  1135. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1136.  
  1137. inline complex<long double> _VFAR & __cmo complex<long double>::operator-= (complex<float> _VFARC & __s2)
  1138. {    Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1139.  
  1140. inline complex<long double> _VFAR & __cmo complex<long double>::operator-= (complex<double> _VFARC & __s2)
  1141. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1142.  
  1143. inline complex<long double> _VFAR & __cmo complex<long double>::operator-= (complex<long double> _VFARC & __s2)
  1144. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1145.  
  1146. inline complex<float> _VFAR & __cmo complex<float>::operator*= (complex<float> _VFARC & __fac2)
  1147. {   float tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1148.     Im          = Im * __fac2.Re + Re * __fac2.Im;
  1149.     Re          = tmpRe;
  1150.     return *this;
  1151. }
  1152.  
  1153. inline complex<float> _VFAR & __cmo complex<float>::operator*= (complex<double> _VFARC & __fac2)
  1154. {   float tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1155.     Im          = Im * __fac2.Re + Re * __fac2.Im;
  1156.     Re          = tmpRe;
  1157.     return *this;
  1158. }
  1159.  
  1160. inline complex<float> _VFAR & __cmo complex<float>::operator*= (complex<long double> _VFARC & __fac2)
  1161. {   float tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1162.     Im          = Im * __fac2.Re + Re * __fac2.Im;
  1163.     Re          = tmpRe;
  1164.     return *this;
  1165. }
  1166.  
  1167. inline complex<double> _VFAR & __cmo complex<double>::operator*= (complex<float> _VFARC & __fac2)
  1168. {   double tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1169.     Im           = Im * __fac2.Re + Re * __fac2.Im;
  1170.     Re           = tmpRe;
  1171.     return *this;
  1172. }
  1173.  
  1174. inline complex<double> _VFAR & __cmo complex<double>::operator*= (complex<double> _VFARC & __fac2)
  1175. {   double tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1176.     Im           = Im * __fac2.Re + Re * __fac2.Im;
  1177.     Re           = tmpRe;
  1178.     return *this;
  1179. }
  1180.  
  1181. inline complex<double> _VFAR & __cmo complex<double>::operator*= (complex<long double> _VFARC & __fac2)
  1182. {   double tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1183.     Im           = Im * __fac2.Re + Re * __fac2.Im;
  1184.     Re           = tmpRe;
  1185.     return *this;
  1186. }
  1187.  
  1188. inline complex<long double> _VFAR & __cmo complex<long double>::operator*= (complex<float> _VFARC & __fac2)
  1189. {   long double tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1190.     Im                = Im * __fac2.Re + Re * __fac2.Im;
  1191.     Re                = tmpRe;
  1192.     return *this;
  1193. }
  1194.  
  1195. inline complex<long double> _VFAR & __cmo complex<long double>::operator*= (complex<double> _VFARC & __fac2)
  1196. {   long double tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1197.     Im                = Im * __fac2.Re + Re * __fac2.Im;
  1198.     Re                = tmpRe;
  1199.     return *this;
  1200. }
  1201.  
  1202. inline complex<long double> _VFAR & __cmo complex<long double>::operator*= (complex<long double> _VFARC & __fac2)
  1203. {   long double tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1204.     Im                = Im * __fac2.Re + Re * __fac2.Im;
  1205.     Re                = tmpRe;
  1206.     return *this;
  1207. }
  1208.  
  1209. inline complex<float> _VFAR & __cmo complex<float>::operator/= (complex<float> _VFARC & __divisor)
  1210. {     double denom;
  1211.       float  tmpRe = (float)((Re * __divisor.Re + Im * __divisor.Im) /
  1212.             (denom = (double)(__divisor.Re) * __divisor.Re +
  1213.                      (double)(__divisor.Im) * __divisor.Im));
  1214.       Im = (float)((Im * __divisor.Re - Re * __divisor.Im ) / denom);
  1215.       Re = tmpRe;
  1216.       return *this;
  1217. }
  1218.  
  1219. inline complex<float> _VFAR & __cmo complex<float>::operator/= (complex<double> _VFARC & __divisor)
  1220. {     long double denom;
  1221.       float tmpRe = (float)((Re * __divisor.Re + Im * __divisor.Im) /
  1222.            (denom = (long double)(__divisor.Re) * __divisor.Re +
  1223.                     (long double)(__divisor.Im) * __divisor.Im));
  1224.       Im = (float)((Im * __divisor.Re - Re * __divisor.Im ) / denom);
  1225.       Re = tmpRe;
  1226.       return *this;
  1227. }
  1228.  
  1229. inline complex<float> _VFAR & __cmo complex<float>::operator/= (complex<long double> _VFARC & __divisor)
  1230. {   return(*this = complex<long double>(*this) / __divisor); }
  1231.  
  1232.  
  1233. inline complex<double> _VFAR & __cmo complex<double>::operator/= (complex<float> _VFARC & __divisor)
  1234. {     double denom;
  1235.       double tmpRe = (double)((Re * __divisor.Re + Im * __divisor.Im) /
  1236.             (denom = (double)(__divisor.Re) * __divisor.Re +
  1237.                      (double)(__divisor.Im) * __divisor.Im));
  1238.       Im = (Im * __divisor.Re - Re * __divisor.Im ) / denom;
  1239.       Re = tmpRe;
  1240.       return *this;
  1241. }
  1242.  
  1243. inline complex<double> _VFAR & __cmo complex<double>::operator/= (complex<double> _VFARC & __divisor)
  1244. {     long double denom;
  1245.       double  tmpRe = (double)((Re * __divisor.Re + Im * __divisor.Im) /
  1246.              (denom = (long double)(__divisor.Re) * __divisor.Re +
  1247.                       (long double)(__divisor.Im) * __divisor.Im));
  1248.       Im = (double)((Im * __divisor.Re - Re * __divisor.Im ) / denom);
  1249.       Re = tmpRe;
  1250.       return *this;
  1251. }
  1252.  
  1253. inline complex<double> _VFAR & __cmo complex<double>::operator/= (complex<long double> _VFARC & __divisor)
  1254. {   return(*this = complex<long double>(*this) / __divisor); }
  1255.  
  1256. inline complex<long double> _VFAR & __cmo complex<long double>::operator/= (complex<float> _VFARC & __divisor)
  1257. {     double denom;
  1258.       long double tmpRe = (Re * __divisor.Re + Im * __divisor.Im) /
  1259.                  (denom = (double)(__divisor.Re) * __divisor.Re +
  1260.                           (double)(__divisor.Im) * __divisor.Im);
  1261.       Im = (Im * __divisor.Re - Re * __divisor.Im ) / denom;
  1262.       Re = tmpRe;
  1263.       return *this;
  1264. }
  1265.  
  1266. inline complex<long double> _VFAR & __cmo complex<long double>::operator/= (complex<double> _VFARC & __divisor)
  1267. {     long double denom;
  1268.       long double tmpRe = (Re * __divisor.Re + Im * __divisor.Im) /
  1269.                  (denom = (long double)(__divisor.Re) * __divisor.Re +
  1270.                           (long double)(__divisor.Im) * __divisor.Im);
  1271.       Im = (Im * __divisor.Re - Re * __divisor.Im ) / denom;
  1272.       Re = tmpRe;
  1273.       return *this;
  1274. }
  1275.  
  1276. inline complex<long double> _VFAR & __cmo complex<long double>::operator/= (complex<long double> _VFARC & __divisor)
  1277. {   return(*this = (*this) / __divisor); }
  1278.  
  1279. template <class T>
  1280. inline istream _VFAR &  __cmf operator>> (istream _VFAR & is, complex<T> _VFAR & __z)
  1281. {   // read a complex number __z in the form r or (r) or {r, i} or (r, i)
  1282.     T     r = 0, i = 0;
  1283.     char  c;
  1284.  
  1285.     is >> c;
  1286.     if (c == '(' || c == '{')  // notations (r), (r,i), or {r,i}
  1287.     {
  1288.         is >> r >> c;
  1289.         if (c == ',') { is >> i  >> c;}
  1290.         if (c != ')' && c != '}')   is.clear(ios::failbit);
  1291.     }
  1292.     else  // only real part
  1293.     {
  1294.         is.putback(c);
  1295.         is >> r;
  1296.     }
  1297.     if (is) { __z.Re = r; __z.Im = i; }
  1298.     return is;
  1299. }
  1300.  
  1301. template <class T>
  1302. inline ostream _VFAR &  __cmf operator<< (ostream _VFAR & os, complex<T> _VFARC & __z)
  1303. {   return os << "{" << __z.Re << "," << __z.Im << "}"; }
  1304.  
  1305. #endif // CMATH_CLASSIC_COMPLEX
  1306. #ifdef __BORLANDC__
  1307.       #pragma option -a.
  1308. #else /* Visual C++ */
  1309.       #pragma pack( pop )
  1310. #endif    /* restore default data packing  */
  1311.  
  1312.        // error handling functions, borrowed from VectorLib:
  1313. extern "C" {
  1314. void  __cmf  V_noteError( char _VFAR *fname, unsigned why );
  1315. void  __cmf  V_printErrorMsg( char _VFAR *ErrMsg );
  1316. void  __cmf  V_setErrorEventFile( char _VFAR *filename,  unsigned ScreenAndFile );
  1317. void  __cmf  V_closeErrorEventFile( void );
  1318.  
  1319. /*** translation of calls to matherr() into _matherr() for BorlandC 4.0+ ***
  1320.  ***  (necessary only to maintain compatibility with BorlandC 3.x)       ***/
  1321.  
  1322. #if (__BORLANDC__ >= 0x450) && !defined (__FLAT__)
  1323.      #if !defined( __MATH_H )
  1324.             #include <math.h>
  1325.      #endif
  1326.      int  _Cdecl _FARFUNC matherr (struct exception _VFAR *__e);
  1327.      #define NEWMATHERR  \
  1328.          int matherr( struct exception _VFAR *__e ) \
  1329.          {  return( _matherr( __e )); }
  1330. #else
  1331.      #define NEWMATHERR
  1332. #endif
  1333. }  // end of extern "C" statement
  1334.  
  1335. #undef VBOOL
  1336. #undef __cmf
  1337. #undef __cmo
  1338. typedef fComplex fcomplex;
  1339. typedef dComplex dcomplex;
  1340. typedef eComplex ecomplex;  // tolerate all-lower case
  1341. #endif  // __NEWCPLX_H
  1342.